//util.js中
//渲染表格传list，新增行传list和row
export function projectTargetList(list, row) {
    let newList = []
    if (row) {
        list.push(row)
    }
    // 按照 type 属性分类
    let classifiedObject = list.reduce(function (acc, obj) {
        let key = obj.address;
        if (!acc[key]) {
            acc[key] = { type: key, child: [] };
        }
        acc[key].child.push(obj);
        return acc;
    }, {});
    let tempList = Object.values(classifiedObject);
    // console.log(tempList);
    //计算startRow和endRow值
    let tempList2 = tempList.reduce(function (acc, obj, index) {
        let startRow = (index == 0) ? 0 : acc[index - 1].endRow; // 计算 startRow
        let endRow = startRow + obj.child.length; // 计算 endRow
        let rows = obj.child.length
        obj.startRow = startRow;
        obj.endRow = endRow;
        obj.rows = rows
        acc.push(obj);
        return acc;
    }, []);
    // console.log(tempList2);
    tempList2.forEach((item, index) => {
        item.child.forEach((citem, cindex) => {
            citem.startRow = item.startRow
            citem.endRow = item.endRow
            citem.rows = item.rows
            newList.push(citem)
        })
    })
    // console.log(newList);
    return newList
}